package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.mapper.ItemMapper;
import com.woniu.mapper.PackageItemContactMapper;
import com.woniu.pojo.Item;
import com.woniu.pojo.Package;
import com.woniu.mapper.PackageMapper;
import com.woniu.pojo.PackageItemContact;
import com.woniu.service.IPackageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务包表 服务实现类
 * </p>
 *
 * @author YMY
 * @since 2022-10-12
 */
@Service
public class PackageServiceImpl extends ServiceImpl<PackageMapper, Package> implements IPackageService {

    @Resource
    private PackageMapper packageMapper;
    @Resource
    private PackageItemContactMapper packageItemContactMapper;
    @Resource
    private ItemMapper itemMapper;

    /**
     * 根据服务包ID查询所有的服务项目
     * @param packageId
     * @return
     */
    @Override
    public List<Item> queryItemByPackage(Long packageId) {
        List<Item> itemList = new ArrayList<>();
        QueryWrapper<PackageItemContact> wrapper = new QueryWrapper<>();
        wrapper.eq("package_id",packageId);
        List<PackageItemContact> packageItemContactList = packageItemContactMapper.selectList(wrapper);

        for (PackageItemContact packageItemContact : packageItemContactList) {
            Item item = itemMapper.selectById(packageItemContact.getItemId());
            itemList.add(item);
        }
        return itemList;
    }
}
